<template>
  <div>
    <van-form @submit="onSubmit">
      <van-nav-bar
        class="am-navbar"
        title="账号登录"
        left-arrow
        @click-left="onClickLeft"
      />
      <van-field
        class="Login_input__2pNlW"
        v-model="username"
        name="username"
        placeholder="请输入账号"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        class="Login_input__2pNlW"
        v-model="password"
        type="password"
        name="password"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button block type="info" native-type="submit" class="login"
          >登录</van-button
        >
      </div>
      <router-link class="link" to="/enroll">还没有账号,去注册~</router-link>
    </van-form>
  </div>
</template>

<script>
import {login} from "@/api/user";
import {setToken} from "@/utils/storage"

export default {
  name: "login-",

  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
   async onSubmit(values) {
      // console.log("submit", values);
      const data = await login(values)
      console.log(data.body.token);
      setToken(data.body.token)
      this.$toast('登陆成功')
    },
    
    onClickLeft() {
      this.$router.go(-1);
      this.$toast("返回");
    },
  },
};
</script>

<style scoped>
.link {
  color: #666;
  font-size: 16px;
  padding-left: 120px;
}

.login {
  display: block;
  outline: 0 none;
  -webkit-appearance: none;
  padding: 0;
  text-align: center;
  font-size: 18px;
  height: 50px;
  line-height: 50px;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
  white-space: nowrap;
  color: #fff;
  background-color: #1cb676;
  border: 1px solid #1cb676;
  border-radius: 2px;
  width: 100%;
}

.Login_input__2pNlW {
  height: 60px;
  width: 100%;
  padding: 2px 0;
  border: 0;
  /* color: #000; */
  font-size: 17px;
  background-color: transparent;
}

.am-navbar {
  align-items: center;
  height: 45px;
  background-color: #21b97a;
  color: #fff;
}

/deep/ .van-nav-bar__title {
  color: #fff;
}

/deep/ .van-nav-bar .van-icon {
  color: #fff;
}
</style>
